package com.ccf.business.etl.service.impl;

import com.google.common.collect.Lists;
import com.common.model.pojo.Order;
import com.common.model.result.CodeEnum;
import org.springframework.stereotype.Service;
import com.common.model.result.PageResult;
import com.common.model.pojo.Query;
import com.service.mybatis.util.Condition;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.service.mybatis.service.impl.SuperServiceImpl;

import lombok.extern.slf4j.Slf4j;

import com.ccf.business.etl.model.Component;
import com.ccf.business.etl.mapper.ComponentMapper;
import com.ccf.business.etl.service.IComponentService;

import java.util.List;

/**
 * 组件表
 *
 * @author ccf
 * @date 2021-11-25 15:36:06
 */
@Slf4j
@Service
public class ComponentServiceImpl extends SuperServiceImpl<ComponentMapper, Component> implements IComponentService {


    /**
    * 列表
    * @param query
    * @return
    */
    @Override
    public PageResult<Component> findList(Query query){
        //组件默认排序
        List<Order> orders = query.filterNullOrders();
        if (orders == null){
            query.setOrders(Lists.newArrayList(new Order("sort", true)));
        } else {
            orders.add(new Order("sort", true));
            query.setOrders(orders);
        }
        Page<Component> page = page(Condition.getPage(query), Condition.getQueryWrapper(query));
        return PageResult.<Component>builder().datas(page.getRecords()).code(CodeEnum.SUCCESS.getCode()).count(page.getTotal()).build();
    }

    @Override
    public void clear() {
        baseMapper.clear();
    }
}
